package com.usts.ms.service.impl;

import com.usts.ms.mapper.CustomerMapper;
import com.usts.ms.model.Customer;
import com.usts.ms.model.QueryVo;
import com.usts.ms.service.CustomerService;
import com.usts.ms.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lenovo on 2019/5/14.
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public Page<Customer> getCustomerByQueryVo(QueryVo vo) {

        //计算分页查询从哪条记录开始
        vo.setStart((vo.getPage() - 1) * vo.getRows());

        //查询总记录数
        Integer total = customerMapper.getCountByQueryVo(vo);

        //查询每一页列表
        List<Customer> list = customerMapper.getCustomerByQueryVo(vo);

        //包装分页数据
        Page<Customer> page = new Page<>(total,vo.getPage(),vo.getRows(),list);

        return page;
    }

    @Override
    public Customer getCustomerById(Integer id) {
        return customerMapper.getCustomerById(id);
    }

    @Override
    public void updateCustomer(Customer customer) {
        customerMapper.updateCustomer(customer);
    }

    @Override
    public void deleteCustomerById(Integer id) {
        customerMapper.deleteCustomerById(id);
    }
}
